﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UseCase.Messages.cs" company="">
//   
// </copyright>
// <summary>
//   The use case.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.UseCases
{
    using System.Collections.Generic;

    /// <summary>
    ///   The use case.
    /// </summary>
    public abstract partial class UseCase
    {
        // Error
        #region Methods

        /// <summary>
        /// The error.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="commands">
        /// The commands. 
        /// </param>
        /// <param name="defaultCommand">
        /// The default command. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition Error(
            string text, IEnumerable<CommandDefinition> commands, CommandDefinition defaultCommand = null)
        {
            return this.Message(text, MessageType.Error, commands, defaultCommand);
        }

        /// <summary>
        /// The error with cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        protected void ErrorWithCancel(string text)
        {
            this.Error(text, new[] { StandardCommandDefinitions.CancelCommand });
        }

        /// <summary>
        /// The error with ignore cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition ErrorWithIgnoreCancel(string text)
        {
            return this.Error(
                text, new[] { StandardCommandDefinitions.IgnoreCommand, StandardCommandDefinitions.CancelCommand });
        }

        /// <summary>
        /// The error with ok.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        protected void ErrorWithOk(string text)
        {
            this.Error(text, new[] { StandardCommandDefinitions.OkCommand });
        }

        /// <summary>
        /// The error with retry cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition ErrorWithRetryCancel(string text)
        {
            return this.Error(
                text, new[] { StandardCommandDefinitions.RetryCommand, StandardCommandDefinitions.CancelCommand });
        }

        /// <summary>
        /// The error with retry ignore cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition ErrorWithRetryIgnoreCancel(string text)
        {
            return this.Error(
                text, 
                new[]
                    {
                        StandardCommandDefinitions.RetryCommand, StandardCommandDefinitions.IgnoreCommand, 
                        StandardCommandDefinitions.CancelCommand
                    });
        }

        /// <summary>
        /// The information.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="commands">
        /// The commands. 
        /// </param>
        /// <param name="defaultCommand">
        /// The default command. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition Information(
            string text, IEnumerable<CommandDefinition> commands, CommandDefinition defaultCommand = null)
        {
            return this.Message(text, MessageType.Information, commands, defaultCommand);
        }

        /// <summary>
        /// The information with ok.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        protected void InformationWithOk(string text)
        {
            this.Information(text, new[] { StandardCommandDefinitions.OkCommand });
        }

        /// <summary>
        /// The message.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="type">
        /// The type. 
        /// </param>
        /// <param name="commands">
        /// The commands. 
        /// </param>
        /// <param name="defaultCommand">
        /// The default command. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected virtual CommandDefinition Message(
            string text, 
            MessageType type, 
            IEnumerable<CommandDefinition> commands, 
            CommandDefinition defaultCommand = null)
        {
            // TODO null???
            var useCase = new MessageUseCase(null, this.Service)
                {
                   Text = text, MessageType = type, Commands = commands, DefaultCommand = defaultCommand 
                };

            return this.Service.ExecuteModalUseCase(useCase);
        }

        // Question

        /// <summary>
        /// The question.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="commands">
        /// The commands. 
        /// </param>
        /// <param name="defaultCommand">
        /// The default command. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition Question(
            string text, IEnumerable<CommandDefinition> commands, CommandDefinition defaultCommand = null)
        {
            return this.Message(text, MessageType.Question, commands, defaultCommand);
        }

        /// <summary>
        /// The question with yes no.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="defaultYes">
        /// The default yes. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition QuestionWithYesNo(string text, bool defaultYes = true)
        {
            return this.Question(
                text, new[] { StandardCommandDefinitions.YesCommand, StandardCommandDefinitions.NoCommand });
        }

        /// <summary>
        /// The question with yes no cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="defaultYes">
        /// The default yes. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition QuestionWithYesNoCancel(string text, bool defaultYes = true)
        {
            return this.Question(
                text, 
                new[]
                    {
                        StandardCommandDefinitions.YesCommand, StandardCommandDefinitions.NoCommand, 
                        StandardCommandDefinitions.CancelCommand, 
                    });
        }

        /// <summary>
        /// The warning.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <param name="commands">
        /// The commands. 
        /// </param>
        /// <param name="defaultCommand">
        /// The default command. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition Warning(
            string text, IEnumerable<CommandDefinition> commands, CommandDefinition defaultCommand = null)
        {
            return this.Message(text, MessageType.Warning, commands, defaultCommand);
        }

        /// <summary>
        /// The warning with ok.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        protected void WarningWithOk(string text)
        {
            this.Warning(text, new[] { StandardCommandDefinitions.OkCommand });
        }

        /// <summary>
        /// The warning with ok cancel.
        /// </summary>
        /// <param name="text">
        /// The text. 
        /// </param>
        /// <returns>
        /// The <see cref="CommandDefinition"/> . 
        /// </returns>
        protected CommandDefinition WarningWithOkCancel(string text)
        {
            return this.Message(
                text, 
                MessageType.Warning, 
                new[] { StandardCommandDefinitions.OkCommand, StandardCommandDefinitions.CancelCommand });
        }

        #endregion
    }
}